<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- 车型选择 -->
<script type="text/javascript">
$(document).ready(function () {
	//车品牌/车系/车型选择
    $("#carBrand").change(function(){
    	var carBrand = $("#carBrand").val();
    	selectSeries(carBrand);
    });
    //车系/车型选择
    $("#carSeries").change(function(){
    	var carSeries = $("#carSeries").val();
    	selectCars(carSeries);
    });
    var carBrandCode = $('#carBrandCode').val();
    var carSeriesCode = $('#carSeriesCode').val();
    var carModelCode = $('#carModelCode').val();
    selectSeries(carBrandCode?carBrandCode.trim():'', carSeriesCode?carSeriesCode.trim():'', carModelCode?carModelCode.trim():'');
});

function selectSeries(carBrand, carSeries, carModel) {
	if(!carBrand || carBrand == '') {return;}
	$.dpAjax({
		show:false,
    	url:'${basePath}/YwBusinessCarAreaPriceController/selectSeries',
			data:{brandId:carBrand,xlid:carSeries},
			success: function(datas){
 				 var juheSeries = datas.result.juheSeries;
 				 var serieshtml = "";
 				 var firstSeriesFlag = true;
 				  for(var i in juheSeries) {
 					  if(firstSeriesFlag && !carSeries) {
 						 firstSeriesFlag = false;
 						 serieshtml += "<option value='" +i+ "' selected>" + juheSeries[i]+ "</option>";
 					  } else if(carSeries && carSeries == i){
 						 serieshtml += "<option value='" +i+ "' selected>" + juheSeries[i]+ "</option>";
 					  } else {
 						 serieshtml += "<option value='" +i+ "'>" + juheSeries[i]+ "</option>";
 					  }
 				  }
 				 $("#carSeries").html(serieshtml);
 				 
 				 var juheCars = datas.result.juheCars;
 				 var carModelshtml = "";
 				 var firstFlag = true;
 				 for(var i in juheCars) {
 					if(firstFlag && !carModel) {
     					firstFlag = false;
     					carModelshtml += "<option value='" +i+ "' selected>" + juheCars[i]+ "</option>";
 					} else if(carModel && carModel == i){
 						carModelshtml += "<option value='" +i+ "' selected>" + juheCars[i]+ "</option>";
 					} else {
 						carModelshtml += "<option value='" +i+ "'>" + juheCars[i]+ "</option>";
 					}
 				  }
 				  $("#carModel").html(carModelshtml);
         }
    });
}
function selectCars(carSeries, carModel){
	if(!carSeries || carSeries == '') {return;}
	$.dpAjax({
		async:false,
		show:false,
    	url:'${basePath}/YwBusinessCarAreaPriceController/selectCars',
			data:{xlid:carSeries},
			success: function(datas){
				 var juheCars = datas.result;
				 var html = "";
				 var firstFlag = true;
				  for(var i in juheCars) {
					if(firstFlag && !carModel) {
						firstFlag = false;
				  		html += "<option value='" +i+ "' selected>" + juheCars[i]+ "</option>";
					} else if(carModel && carModel == i){
						html += "<option value='" +i+ "' selected>" + juheCars[i]+ "</option>";
					} else {
						html += "<option value='" +i+ "'>" + juheCars[i]+ "</option>";
					}
				  }
			  	$("#carModel").html(html);
        }
    });
}
</script>